<html>
<head>
    <!-- 最新版本的 Bootstrap 核心 CSS 文件 -->
    <link href="${ctx}/bootstrap/3.3.7/css/bootstrap.min.css" rel="stylesheet">
    <link href="${ctx}/font-awesome/3.0.0/css/font-awesome.min.css" rel="stylesheet">
    <link href="${ctx}/css/index.css" rel="stylesheet">
    <!-- font -->
    <link href="${ctx}/font-awesome/3.0.0/css/font-awesome.min.css" rel="stylesheet">
    <link href="${ctx}/bootstrap-table/1.12.0/bootstrap-table.min.css" rel="stylesheet">
    <script src="${ctx}/jquery/2.1.4/jquery.min.js"></script>
    <!-- 最新的 Bootstrap 核心 JavaScript 文件 -->
    <script src="${ctx}/bootstrap/3.3.7/js/bootstrap.min.js"></script>
    <script src="${ctx}/bootstrap-table/1.12.0/bootstrap-table.min.js"></script>

    <script src="${ctx}/layui/layui.all.js"></script>

    <link href="${ctx}/layui/css/layui.css" rel="stylesheet">
    <script src="${ctx}/js/util.js"></script>
</head>
<body>
<div style="padding: 10px 15px">
    <div class="layui-inline">
        <label class="layui-form-label" style="width: 120px">开始时间</label>
        <div class="layui-input-inline">
            <input type="text" class="layui-input" id="star" placeholder="请选择时间">
        </div>
    </div>
    <div class="layui-inline">
        <label class="layui-form-label" style="width: 120px">结束时间</label>
        <div class="layui-input-inline">
            <input type="text" class="layui-input" id="end" placeholder="请选择时间">
        </div>
    </div>

    <div class="btn-group">
        <span id="search_btn" class="btn btn-info" style="height: 38px;margin: -10px 0 0 10px">查询</span>
    </div>
    <table class="table table-border table-bordered table-hover table-bg table-sort" id="layTable"
           lay-filter="tableFilter">

    </table>
</div>

</body>

<script src="${ctx}/bootstrap-table/1.12.0/locale/bootstrap-table-zh-CN.min.js"></script>
<script src="${ctx}/bootstrap-table/1.12.0/extensions/export/bootstrap-table-export.min.js"></script>
<script src="${ctx}/js/extends.js"></script>
<script type="text/html" id="barDemo">
    <a class="layui-btn layui-btn-xs " lay-event="lookDetail">查看记录</a>
</script>
<script>
    var star = '';
    var end = '';
    layui.use('laydate', function () {
        var laydate = layui.laydate;
        laydate.render({
            elem: '#star'
            , type: 'datetime'

        });
        laydate.render({
            elem: '#end'
            , type: 'datetime'

        });
    });
    let table = "tb_member_record";

    layui.use('form', function () {
        var form = layui.form;
        form.render();
        //监听提交
        form.on('submit(formDemo)', function (data) {
            layer.msg(JSON.stringify(data.field));
            return false;
        });
    });
    layui.use('table', function () {
        tableIns = layui.table;
        form = layui.form;
        tableIns.render({
            elem: '#layTable'
            ,
            url: '/record/detail?tableName=${tableName}&taskId=${taskId}'
            ,
            method: 'POST'
            ,
            toolbar: true
            ,
            totalRow: true
            ,
            where: {
                table: table, star: star, end: end
            }
            ,
            id: 'dataTableId'
            ,
            cols: [[
                {
                    type: 'checkbox', field: 'id'
                }
                , {
                    field: 'createTime',
                    title: '领取时间',
                    width: 200,
                    align: 'center',
                    sort: true,
                    templet: function (data) {
                        return dateFormat(data.create_time);
                    }
                }
                , {
                    field: 'submit_time',
                    title: '提交时间',
                    width: 200,
                    align: 'center',
                    sort: true,
                    templet: function (data) {
                        return dateFormat(data.submit_time);
                    }
                }
                , {field: 'imei', title: 'IMEI', width: 150, align: 'center', sort: true}
                , {field: 'mac_addr', title: 'MAC', width: 150, align: 'center', sort: true}
                , {field: 'ip_addr', title: 'IP', width: 150, align: 'center', sort: true}
                , {field: 'worth', title: '金额', width: 100, align: 'center', sort: true, totalRow: true}

            ]]
            ,
            page: true
        });
        $("#search_btn").click(function () {
            reload();

        });

        tableIns.on('checkbox(tableFilter)', function (obj) {
            var checkStatus = tableIns.checkStatus('dataTableId');
            var dataList = checkStatus.data;
            if (dataList != null && dataList.length > 0) {

                for (var i = 0; i < dataList.length; i++) {
                    ids += dataList[i].id + ",";
                }
            }
        });

        function deleteId(ids) {
            if (ids != "") {
                $.ajax({
                    url: "/delete/data",
                    type: 'post',
                    data: {"table": table, "ids": ids},
                    async: false,
                    dataType: "json",
                    success: function (arg) {
                        if (arg) {
                            layer.msg(arg.message);
                            reload();
                        } else {
                            layer.msg(arg.message);
                        }
                    }
                });
            }
        }

        $("#multiDelete").click(function () {
            deleteId(ids)
        });

        tableIns.on('tool(tableFilter)', function (obj) {
            var data = obj.data;
            if (obj.event === 'detail') {
                layer.msg('ID：' + data.id + ' 的查看操作');
            } else if (obj.event === 'del') {
                if (data.has_deleted == 1) {
                    layer.msg('已删除，不可进行该操作!', {icon: 1, time: 1000});
                    return;
                }
                layer.confirm('真的删除行么', function (index) {
                    deleteId(data.id)
                    layer.close(index);
                });
            } else if (obj.event === 'edit') {
                if (data.has_deleted == 1) {
                    layer.msg('已删除，不可进行该操作!', {icon: 1, time: 1000});
                    return;
                }
                layer_show("修改", "/financeRecord/edit?id=" + data.id, "550", "650");
                parent.search();
            } else if (obj.event === 'rwjl') {
                records(data.memberId)
            } else if (obj.event === 'shenhe') {
                layer.confirm('请审核', {
                    btn: ['通过', '拒绝', '取消'] //可以无限个按钮
                    , btn3: function (index, layero) {
                        //按钮【按钮三】的回调
                        layer.close(index);
                    }
                }, function (index, layero) {
                    layer.close(index);
                    //按钮【按钮一】的回调
                    pass(data.id);
                }, function (index) {
                    layer.close(index);
                    //按钮【按钮二】的回调
                    repulse(data.id);
                });
            } else if (obj.event === 'lookDetail') {
                lookDetail(data.task_id)
            }
        });
    });

    function queryParams(opt) {
        opt.search = $("#search").val();
        opt.order = 'desc';
        return opt;
    };


    function lookDetail(taskId) {

    }

    function reload() {
        tableName = $("#tableName").val();
        title = $("#title").val();
        customerid = $("#customerid").val();
        star = $("#star").val();
        end = $("#end").val();
        tableIns.reload('dataTableId', {
            where: {
                tableName: tableName
                , title: title
                , customerid: customerid
                , star: star
                , end: end
            }
            , page: {
                curr: 1
            }
        });
    }
</script>
</body>
</html>